package student;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;

public class socket {
	
	//创建客户端
	/*A.主线程用于发送数据
	 * B.自定义线程用于接收数据
	 * */
	public static void ma() {
		//建立Socket发送数据到客户端
		Socket socket=null;
		BufferedReader br=null;
		BufferedWriter bw=null;
		try {

			
			socket=new Socket("10.96.114.28",10010);
			
			//创建线程接收数据
			Thread th=new Thread(new socketThread(socket));
			th.start();
			
			//创建数据，并发送
			br=new BufferedReader(new InputStreamReader(System.in));
			bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
			while(true) {
			String line=br.readLine();
			bw.write(line);
			bw.newLine();	
			bw.flush();
			
			}
		
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				
				socket.close();
				bw.close();
				br.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		
		
	}
	
	
}
